package com.ruoyi.backend.controller;

import com.ruoyi.backend.domain.ServiceItem;
import com.ruoyi.backend.service.IServiceItemService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务管理Controller
 *
 * @author 王冰冰
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/serviceManagement")
public class ServiceItemController extends BaseController {
    @Autowired
    private IServiceItemService serviceItemService;

    /**
     * 查询服务管理列表
     */
    @RequiresPermissions("serviceManagement:serviceManagement:list")
    @GetMapping("/list")
    public TableDataInfo list(ServiceItem serviceItem) {
        startPage();
        List<ServiceItem> list = serviceItemService.selectServiceItemList(serviceItem);
        return getDataTable(list);
    }

    /**
     * 导出服务管理列表
     */
    @RequiresPermissions("serviceManagement:serviceManagement:export")
    @Log(title = "服务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceItem serviceItem) {
        List<ServiceItem> list = serviceItemService.selectServiceItemList(serviceItem);
        ExcelUtil<ServiceItem> util = new ExcelUtil<ServiceItem>(ServiceItem.class);
        util.exportExcel(response, list, "服务管理数据");
    }

    /**
     * 获取服务管理详细信息
     */
    @RequiresPermissions("serviceManagement:serviceManagement:query")
    @GetMapping(value = "/{serviceId}")
    public AjaxResult getInfo(@PathVariable("serviceId") Long serviceId) {
        return success(serviceItemService.selectServiceItemByServiceId(serviceId));
    }

    /**
     * 新增服务管理
     */
    @RequiresPermissions("serviceManagement:serviceManagement:add")
    @Log(title = "服务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceItem serviceItem) {
        return toAjax(serviceItemService.insertServiceItem(serviceItem));
    }

    /**
     * 修改服务管理
     */
    @RequiresPermissions("serviceManagement:serviceManagement:edit")
    @Log(title = "服务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceItem serviceItem) {
        return toAjax(serviceItemService.updateServiceItem(serviceItem));
    }

    /**
     * 删除服务管理
     */
    @RequiresPermissions("serviceManagement:serviceManagement:remove")
    @Log(title = "服务管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceIds}")
    public AjaxResult remove(@PathVariable Long[] serviceIds) {
        return toAjax(serviceItemService.deleteServiceItemByServiceIds(serviceIds));
    }
}